<?php
/*************************************************************************
 *
 *  System Name     ： UI TOOL
 *  Include Name  	： Template.class.php
 *  Include IＤ		： Template
 *
 *  Writer          ： Minz
 *  Create Date		： 2011/10/20
 *
 *************************************************************************/




/*************************************************************************

	COMMON INCLUDE

**************************************************************************/

include dirname(__file__).'/Template_.class.php';
include dirname(__file__).'/class.db.php';
include dirname(__file__).'/class.javascript.php';
include dirname(__file__).'/class.LevelChecker.php';
include dirname(__file__).'/message_form.php';
include dirname(__file__).'/config.php';
include dirname(__file__).'/Sajax.php';

session_start();
/*************************************************************************

	TEMPLATE_ SETTING CLASS

**************************************************************************/

class Template extends Template_
{

	var $compile_check =true;
	var $compile_dir   ='D:\workspace_php\UI_TOOL\cmpl';
//	var $compile_dir   ='/WWW/synonim_editor/cmpl';
	var $compile_ext   ='php';
	var $skin          ='';
	var $template_dir  ='D:\workspace_php\UI_TOOL\web\_tmpl';
//	var $template_dir  ='/WWW/synonim_editor/web/_tmpl';
	var $prefilter     ='adjustPath';

	function Template($skin='')
	{
		if ($skin) $this->skin = $skin;
	}

	function setDefine($body ,$sub="/submenu.html"){
		global $userscript;

		$this->define(array(
				    'header'  => 'header.html',
					'main' => $body,
				    'footer'=>'footer.html',
				));
		$this->assign('userscript',$userscript);
	}
	function setPrint(){

		$this->print_('header');
		$this->print_('main');
		$this->print_('footer');
	}

	function setDefine2($body){
		global $userscript;
		$this->define(array(
					'main' => $body
				));
		$this->assign('userscript',$userscript);
	}
	function setPrint2(){
		$this->print_('main');
	}

}


/*************************************************************************

	COMMON FUNCTION

**************************************************************************/

function print_rr($in)
{
	global $debug_mode_value;

	if(!empty($debug_mode_value)){
		echo "<pre>";
		print_r($in);
		echo "</pre>";
	}
}
function echoo($in)
{
	global $debug_mode_value;

	if(!empty($debug_mode_value)){
		echo("<br>$in<br>");
	}
}

function Unescape($str){
    return urldecode(preg_replace_callback('/%u([[:alnum:]]{4})/', 'UnescapeFunc', $str));
}

function UnescapeFunc($str){
    return mb_convert_encoding(chr(hexdec(substr($str[1], 2, 2))).chr(hexdec(substr($str[1],0,2))), 'UTF-8', 'UTF-16LE');
}

function cut_string($in_str,$cnt){
	$out_str="";

	if(mb_strlen($in_str,'UTF-8') > $cnt){
		$out_str = mb_substr($in_str,0,$cnt,'UTF-8').'…';
	}else if(mb_strlen($in_str,'UTF-8') == 0){
		$out_str = "　";
	}else{
		$out_str = $in_str;
	}
	return $out_str;
}
function numberFormat($num,$formatType=""){
	$arrNumber = explode('.',$num);
	if(count($arrNumber)>1){
		if($arrNumber[1] > 0){
			if($formatType){
				return number_format($arrNumber[0]).".".$arrNumber[1];
			}else{
				return $num;
			}
		}else{
			if($formatType){
				return number_format($arrNumber[0]);
			}else{
				return $arrNumber[0];
			}
		}
	}else{
		if($formatType){
				return number_format($num);
			}else{
				return $num;
			}
	}
}

function get_noticeList($no){
	global $db;
	$query="SELECT NoticeNo,Title, DATE_FORMAT(InsertDate,'%Y-%m-%d') AS InsertDate " .
			"FROM notice " .
			"WHERE DeleteFlg=0 " .
			"ORDER BY InsertDate DESC " .
			"LIMIT 1 offset $no";
	$db->conn();
	$list = $db->fetch($query);
	$db->close();
	if(!empty($list)){
		$noticeNo=$list['NoticeNo'];
		$title="<a href='../help/notice.php?mode=list&NoticeNo=$noticeNo'>".$list['Title']."</a>";
	}else{
		$title="";
	}
	return $title;
}

function strcut($str, $len) {
	return (!$str) ? '' : (preg_match('/^([\xa1-\xfe]{2}|.){'.$len.'}/s', $str, $m) ? $m[0] . '...' : $str);
}

function checkLogin(){
	global $JSClass;

	if(empty($_SESSION[user_cd])){
		$JSClass->msg_replace("login please!","./login.php");
		exit;
	}
}

?>
